
import { _decorator, Component, Node, SystemEvent } from 'cc';
import { CarManager } from './CarManager';
import { MapManager } from "./MapManager";
const { ccclass, property } = _decorator;

@ccclass('GameCtl')
export class GameCtl extends Component {
    @property({
        type: MapManager
    })
    public mapManager: MapManager = null!;

    @property({
        type: CarManager
    })
    public carManager : CarManager = null!;

    onLoad() {
        this.mapManager.resetMap();
        this.carManager.resetCars(this.mapManager.currPath);

        this.node.on(SystemEvent.EventType.TOUCH_START, this._touchStart, this);
        this.node.on(SystemEvent.EventType.TOUCH_END, this._touchEnd, this);
    }

    private _touchStart(touch: Touch, touchEvent: TouchEvent) {
        this.carManager.controlMoving();
    }

    private _touchEnd(touch: Touch, touchEvent: TouchEvent) {
        this.carManager.controlMoving(false);
    }
}

